/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.platformservice.persistence.api;

import org.proteusframework.platformservice.IServicePlugin;

/**
 * Persistence services provide an abstraction of one or more unique platform managers related to the broad
 * scope of persistence:
 * <ul>
 * <li>{@link IProjectManager}</li>
 * <li>{@link IVFSManager}</li>
 * <li>{@link IMessageBeanManager}</li>
 * <li>{@link IPackageManager}</li>
 * </ul>
 * <p/>
 * Concrete implementations may not fully support all three platform services. A Proteus application built atop the
 * Proteus Platform Services may utilize zero, one, or many persistence services; however, only one persistence service
 * can be defined as the primordial (primary) persistence service. In cases where aggregation needs to occur, create a
 * composed persistence service that internally iterates over one or more secondary persistence services to report the
 * complete set of values.
 * <p/>
 * The primordial persistence service <i>must</i> support project services, and it <i>must</i> be the only persistence
 * service that the application queries for project services. The framework will automatically disable project services
 * on non-primordial persistence service implementations regardless of when they are brought online. In other words, the
 * /proteus.properties file can declare one and only one primordial persistence service under the key
 * <code>org.proteusframework.service.Persistence</code>, as depicted by
 * {@link org.proteusframework.platformservice.IExtendedRuntimeConfiguration#KEY_PERSISTENCE_SERVICE}. Secondary
 * persistence services must be registered implicitly under a
 * {@link org.proteusframework.platformservice.ServiceClassification#Custom} via the
 * {@link org.proteusframework.platformservice.IExtendedRuntimeConfiguration#activateService(org.proteusframework.core.api.model.INamespace, Object, Class)}
 * method. This doesn't preclude callers from accessing the service as an <code>IPersistenceService</code>, but
 * secondary persistence services cannot be accessed via
 * {@link org.proteusframework.platformservice.IExtendedPlatformDelegate#getPersistenceService()}. Instead, access
 * secondary persistence services via
 * {@link org.proteusframework.platformservice.IExtendedPlatformDelegate#getPlatformService(org.proteusframework.core.api.model.INamespace, Class)}.
 */
public interface IPersistenceService
        extends IProjectManager, IMessageBeanManager, IPackageManager, IVFSManager, IServicePlugin
{
    /**
     * Flag that indicates if this persistence service is the primordial, or primary, persistence service.
     *
     * @return true, if this is the primordial persistence service
     */
    boolean isPrimordial();

    /**
     * Narrows the broad persistence service into one of the specific management interfaces.
     *
     * @param managerInterface One of the four <code>*Manager</code> interfaces that <code>IPersistenceService</code>
     *                         extends.
     * @return Narrowed interface that restricts the visibility of the persistence service's full suite of methods
     * @throws IllegalArgumentException when the interface provide is not one of the four <code>*Manager</code>
     *                                  interfaces, or when the underlying concrete persistence service expressly does not support the target narrowed
     *                                  manager.
     */
    <T> T narrow(Class<T> managerInterface) throws IllegalArgumentException;
}
